package com.itheima.Demo3;

public class Poly {
    public static void main(String[] args) {
       // Dog d = new Dog();
       // useAnimal(d);
        useAnimal(new Dog());
        useAnimal(new Cat());
    }
    public static  void useAnimal(Animal a){ //Animal a = new Dog
        a.eat();

        if(a instanceof  Dog){
            Dog d =(Dog) a;
            d.look();
        }
    }
}


abstract class Animal{
    public abstract  void eat();
}


class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }
}

class Dog extends  Animal{
    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }

    public  void look(){
        System.out.println("狗看门");
    }
}


